package behavioralPattern.visitor.example01;

import behavioralPattern.visitor.example01.product.Candy;
import behavioralPattern.visitor.example01.product.Fruit;
import behavioralPattern.visitor.example01.product.Product;
import behavioralPattern.visitor.example01.product.Wine;
import behavioralPattern.visitor.example01.visitor.DiscountVisitor;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

public class Client_02 {
    public static void main(String[] args) {

        Candy candy = new Candy("德芙巧克力", LocalDate.of(2022,5,1),10.0);
        Wine wine = new Wine("茅台", LocalDate.of(2022, 5, 1), 1000.0);
        Fruit fruit = new Fruit("草莓", LocalDate.of(2022, 5, 1), 50.0,1);

        List<Product> list = Arrays.asList(candy,wine,fruit);
        DiscountVisitor visitor = new DiscountVisitor(LocalDate.of(2023, 5, 1));

//        for (Product product : list) {
//            visitor.visit(product); // 报错了
//        }

        List<Acceptable> products = Arrays.asList(candy, wine, fruit);
        for (Acceptable product : products) {
            product.accept(visitor);
        }

    }
}
